//
//  NSDate+Extension.m
//  微博2期
//
//  Created by J on 15/12/5.
//
//

#import "NSDate+Extension.h"

@implementation NSDate (Extension)



//判断日期是否是今年
- (BOOL)isThisYear{
    NSCalendar * calendar = [NSCalendar currentCalendar];
    NSCalendarUnit unit =NSCalendarUnitYear ;
    NSDateComponents * createComponents = [calendar components:unit fromDate:self];
    NSDateComponents * nowComponents = [calendar components:unit fromDate:[NSDate date]];//当前时间
    if (createComponents.year == nowComponents.year) {//年相等 YES
        return YES;
    }
    return NO;
    
}


//判读某个时间是否是昨天
- (BOOL)isYesterday{
    NSDate * now =[NSDate date];
    NSDateFormatter * fm =[NSDateFormatter new];
    fm.dateFormat = @"yyyy-MM-dd";
    //    通过时间戳 去掉时分秒 只比较天
   NSDate *  date =[fm dateFromString:[fm stringFromDate:self]];//创建时间
    now =[fm dateFromString:[fm stringFromDate:now]];//当前时间
    NSCalendar * calendar = [NSCalendar currentCalendar];
    NSCalendarUnit unit =NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay;
    NSDateComponents * cmps =  [calendar components:unit fromDate:date toDate:now options:0];
    return cmps.year ==0&&cmps.month ==0 &&cmps.day ==1;
    
}

//判读某个时间是否是今天
- (BOOL)isToday{
    NSDate * now =[NSDate date];
    NSDateFormatter * fm =[NSDateFormatter new];
    fm.dateFormat = @"yyyy-MM-dd";
    return [[fm stringFromDate:self] isEqualToString:[fm stringFromDate:now]];
}



@end
